import corejuliano.designpattern.observer.*;


class corejuliano.designpattern.observer.Observable  implements Observer
{
	private var observers:Array; 
	
	public function Observable()
	{
		observers = new Array();
	}
	
	public function addObserver(observer:Observer):Void
	{
		observers.push(observer);
	}
	
	public function removeObserver(observer:Observer):Void
	{
		for (var i:Number = observers.length -1; i >= 0; i--)
			if (observers[i] == observer)
				observers[i].slice(i,1);
		
	}
	
	public function update(event:String, observable:Observable):Void
	{
		
	}
	
	public function notifyObservers(event:String):Void
	{
		for (var i:Number = observers.length -1; i >= 0; i--)
			observers[i].update(event,this);
	}
	
	public function destroyObserver():Void
	{
		for (var i:Number = observers.length -1; i >= 0; i--)
			removeObserver(observers[i]);
			
		observers = null;	
	}	
	
	public function toString(Void):String
	{
		return "designpattern.Observable";
	}
	
}